<%@ page import="java.util.Collections" %>
<%@ page import="net.tutwiz.model.Step" %>
<%@ page import="net.tutwiz.model.Tutorial" %>
<%@ page import="com.google.gson.FieldAttributes" %>
<%@ page import="net.tutwiz.model.User" %>
<%@ page import="com.google.gson.GsonBuilder" %>
<%@ page import="com.google.gson.ExclusionStrategy" %>
<%@ page import="com.google.gson.Gson;" %>
<%
	response.setContentType("application/json");
	response.setCharacterEncoding("utf-8");
%>

<%
	String returnValue = "{";
	Tutorial t = (Tutorial)request.getAttribute("parameters");
	returnValue += "\"title\":\""			+ t.getTitle() + "\", ";
	returnValue += "\"description\":\""	+ t.getDescription() + "\", ";
	returnValue += "\"rate\":\""			+ t.getRate() + "\", ";
        returnValue += "\"id\":\""			+ t.getId() + "\", ";
	returnValue += "\"createdAt\":\""			+ t.getCreatedAt() + "\", ";
	returnValue += "\"createdBy\": {";
	returnValue +=					"\"name\":\"" + t.getCreatedBy().getName() + "\", ";
	returnValue +=					"\"id\":\"" + t.getCreatedBy().getID();
	returnValue +=					"\"},";
	returnValue += "\"steps\": [";

	Collections.sort(t.getSteps());
	
	for(Step s : t.getSteps()) {
		returnValue += "{";
		returnValue += "\"id\":\"" + s.getId() + "\",";
		returnValue += "\"title\":\"" + s.getTitle() + "\",";
		returnValue += "\"order\":\"" + s.getStepOrder() + "\"";
		returnValue += "},";

	}
	returnValue = returnValue.substring(0, returnValue.length()-1);
	returnValue += "]}";
		
%>
<%= returnValue %>
